using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserControls_MenuList : System.Web.UI.UserControl
{
    private int _categoryID = -1;

    public int CategoryID
    {
        get {
            if (Request.QueryString["CategoryID"] != null)
            {
               this._categoryID = int.Parse(Request.QueryString["CategoryID"]);
            }
            return this._categoryID;
        }
        set { _categoryID = value; }
    }
    private int _departmentID = -1;

    public int DepartmentID
    {
        get
        {
            if (Request.QueryString["DepartmentID"] != null)
            {
                this._departmentID = int.Parse(Request.QueryString["DepartmentID"]);
            }
            return this._departmentID;
        }
        set { _departmentID = value; }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        list.DataSource = CatalogAccess.GetDepartmentsWidthNumberOfProducts();
        list.DataBind();
    }

    protected override void OnPreRender(EventArgs e)
    {
        list.DataSource = CatalogAccess.GetDepartmentsWidthNumberOfProducts();
        list.DataBind();
        base.OnPreRender(e);
    }


    protected void list_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if ((e.Item.DataItem as DataRowView) != null)
        {
            if (((int)(e.Item.DataItem as DataRowView).Row.ItemArray[0]) == this.DepartmentID)
            {
                list.SelectedIndex = e.Item.ItemIndex;
                //e.Item.Style.Add(HtmlTextWriterStyle.Color, "white");

                if (this.DepartmentID != -1)
                {
                    Control categoryList = this.Page.LoadControl("UserControls/CategoryList.ascx");
                    //categoryList.EnableViewState = true;
                    e.Item.Controls.Add(categoryList);
                    categoryList.DataBind();
                
                    
                }
            }
        }
    }
}
